package online.sixfish.common.utils;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.model.PutObjectRequest;
import com.qcloud.cos.model.PutObjectResult;
import online.sixfish.common.config.CosConfig;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * CosUtil
 * @author sixFish
 * @date 2024/04/25
 */
@Component
public class CosUtil {

    private final COSClient cosClient;

    private final CosConfig cosConfig;

    public CosUtil(COSClient cosClient, CosConfig cosConfig) {
        this.cosClient = cosClient;
        this.cosConfig = cosConfig;
    }

    public PutObjectResult upload(String key, File file) {
        PutObjectRequest request =
                new PutObjectRequest(cosConfig.getBucketName(), key, file);
        return cosClient.putObject(request);
    }
}